package sany.iec.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author 托马斯
 * @Date 2025/7/6 0:01
 * @Description RegieterEnum
 */
@AllArgsConstructor
@Getter
public enum ModbusRegisterEnum {

    HOLD_REGISTER("holdRegister", "保持寄存器（可读可写）"),

    INPUT_REGISTER("inputRegister", "输入寄存器（只可读）"),

    COIL("coil", "线圈（可读可写）"),

    INPUT("input", "离散变量（只可读）"),

    ;

    private final String register;

    private final String description;

    public static ModbusRegisterEnum getModbusRegisterEnum(String regieter) {
        if (StringUtils.isBlank(regieter)) {
            return null;
        }
        for (ModbusRegisterEnum modbusRegisterEnum : ModbusRegisterEnum.values()) {
            if (regieter.toLowerCase().contains(modbusRegisterEnum.getRegister().toLowerCase())) {
                return modbusRegisterEnum;
            }
        }
        return null;
    }

}
